import java.io.*;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.util.*;
import org.math.plot.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import org.jfree.data.*;
import org.jfree.data.statistics.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.time.*;
import org.jfree.data.time.TimeSeriesCollection;
import java.text.SimpleDateFormat;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;

public class DrawRateGraph {
	public final static String biz_file = "C:\\Users\\Administrator\\Desktop\\research\\Yelp\\yelp_business.json";
	public final static String user_file = "C:\\Users\\Administrator\\Desktop\\research\\Yelp\\yelp_user.json";
	public final static String check_file = "C:\\Users\\Administrator\\Desktop\\research\\Yelp\\yelp_checkin.json";
	public final static String review_file = "C:\\Users\\Administrator\\Desktop\\research\\Yelp\\yelp_review.json";
	public final static String res_review_file = "C:\\Users\\Administrator\\Desktop\\research\\Yelp\\yelp_res_review.json";
	ArrayList<String> biz_list; 
	
	public DrawRateGraph(int i){
		JSONParser myParser = new JSONParser();
		BufferedReader br = null;
		biz_list = new ArrayList();
		
		try {
			br = new BufferedReader(new FileReader(biz_file));
			String bizLine="";
			while((bizLine = br.readLine())!=null){
				Object obj = myParser.parse(bizLine);
	 
				JSONObject jsonObject = (JSONObject) obj;
				//String name = (String) jsonObject.get("name");
				
				ArrayList<String> list = (ArrayList)jsonObject.get("categories");
				// Get all restaurants in business file and save the id in the biz_list
				if(list.contains("Restaurants")) biz_list.add((String)jsonObject.get("business_id"));
			}
			br.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		try {
			br = new BufferedReader(new FileReader(res_review_file));
			String reviewLine="";
			//TimeSeries time1 = new TimeSeries("Rate and Time");
			
			while((reviewLine = br.readLine())!=null){
				Object obj = myParser.parse(reviewLine);
	 
				JSONObject jsonObject = (JSONObject) obj;
				//String name = (String) jsonObject.get("name");
				
				if(biz_list.get(i).equals((String)jsonObject.get("business_id"))) {
					System.out.println(jsonObject.get("stars").toString()+" "+(String)jsonObject.get("text"));
				//	SimpleDateFormat df = new SimpleDateFormat("mm/dd/yyyy");
				//	Date dt = df.parse(jsonObject.get("date").toString());
				//	time1.add(new Day(dt.getDay(),dt.getMonth(),dt.getYear()),Double.parseDouble(jsonObject.get("stars").toString()));
					//System.out.println(jsonObject.get("stars").toString());
				}
			}
		/*	TimeSeriesCollection dataset = new TimeSeriesCollection(time1);
			
			 JFreeChart chart = ChartFactory.createTimeSeriesChart(
				        "RateByDate", "Date", "Stars", dataset,
				        true, true, false);
				    
				    //Get the plot and set date format
				    XYPlot plot = chart.getXYPlot();
				    DateAxis axis = (DateAxis) plot.getDomainAxis();
				      axis.setDateFormatOverride(new SimpleDateFormat("MM-dd-yyyy"));

				    // Render the frame
				    ChartFrame chartFrame = new ChartFrame("Simple TimeSeries Chart", chart);
				    chartFrame.setVisible(true);
				    chartFrame.setSize(600, 300);*/
			
		}catch(Exception e){
			
		}
		
	}
	public static void main(String[] args){
		new DrawRateGraph(1);
	}
}

